<?php
##############################################
#
#   后台登入
# @ Time : 2017-1-14 - 上午12:08:08
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Admin\Controller;
use Think\Controller;
use Admin\Model\LoginModel;

class LoginController extends Controller {
	
	/**
	 * 后台登入页
	 */
    public function index(){
    	$this -> display('login');
    }

    /**
     * 后台登入
     */
    public function login(){
        if(!IS_AJAX) return;
        $data['username'] = I('post.username');
        $data['password'] = md5(I('post.password'));
        $login_model = new LoginModel();
        $user_data = $login_model -> getLoginAdminUser($data);
        if($user_data){
            session('meituan_id', $user_data['id']);
            session('meituan_username', $user_data['username']);
            //记录登录时间
            $time = time();
            M('AdminUsers')->where(array('id'=>$user_data['id']))->setField('last_login_time',$time);
            //setcookie('guoqi_time',time()+10, time()+60*60, '/');//十秒不操作退出
            $this -> ajaxReturn(array('status' => 1, 'message' => '登入成功', 'url' => U('Index/index')));
        }else
            $this -> ajaxReturn(array('status' => 2, 'message' => '登入失败'));
    }
	
	//退出后台
	public function loginOut(){
		unset($_SESSION['meituan_id'], $_SESSION['meituan_username']);
		$this -> redirect('index');
	}
}